import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Language } from "../../../../../extend/language/Language";
import { ImagesConst } from "../../../resource/ImagesConst";
import { SGangFightsApplyTeam } from "../../../../../Message/Public/SGangFightsApplyTeam";
import { PlayerMiniInfo } from "../../../model/PlayerMiniInfo";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { ColorConfig } from "../../../resource/ColorConfig";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GangFightsReplyData } from "../data/GangFightsReplyData";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
//class GangFightsApplyCellRenderer
    
    export  class GangFightsApplyCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._campTxt = ObjCreate.createTextField("", 0, 0, 30, 20, this);
            this._campTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._playerTxt = ObjCreate.createTextField("", 30, 0, 150, 20, this);
            this._playerTxt.addEventListener(flash.events.TextEvent.LINK, this.onPlayerTxtClickHandler);
            this._werfareTxt = ObjCreate.createTextField("", 0, 25, 150, 20, this, GlobalStyle.textFormat6);
            this._requestTxt = ObjCreate.createTextField("", 0, 50, 200, 20, this);
            this._requestTxt.addEventListener(flash.events.TextEvent.LINK, this.onRequestTxtClickHandler);
            this._okBtn = ObjCreate.createGButton(Language.getString(69903), 200, 0, 35, 25, this);
            this._okBtn.name = "ok";
            this._okBtn.drawNow();
            this._cancelBtn = ObjCreate.createGButton(Language.getString(69904), 200, 35, 35, 25, this);
            this._cancelBtn.name = "cancel";
            this._cancelBtn.drawNow();
            this._okBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            ObjCreate.createBg(0, 75, this.width, 2, this, ImagesConst.SplitLine);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._msg = arg1 as SGangFightsApplyTeam;
            if (this._msg) 
            {
                this._playerMiniInfo = new PlayerMiniInfo(this._msg.fromMiniPlayer);
                this._requestTxt.htmlText = HTMLUtil.addColor(Language.getString(44415), "#ffffff");
                this._campColor = ColorConfig.instance.getCampColor(this._playerMiniInfo.camp).color;
                this._campName = GameDefConfig.instance.getCampShort(this._playerMiniInfo.camp).name + "•";
                this._campTxt.htmlText = HTMLUtil.addColor(this._campName, this._campColor);
                this._playerTxt.htmlText = HTMLUtil.addColor("<a href=\'event: 0\'><u>" + this._playerMiniInfo.playerName + "</u></a>", "#ffffff") + HTMLUtil.addColor("（" + Language.getStringByParam(44416, this._playerMiniInfo.level) + "·" + this._playerMiniInfo.careerEnableName + "）", "#F1FFB1");
                this._playerTxt.x = this._campTxt.width;
                this._werfareTxt.text = Language.getStringByParam(44417, this._playerMiniInfo.miniPlayer.warfare);
            }
            return;
        }

        /* internal  */onBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=null;
            if (this._playerMiniInfo) 
            {
                loc1 = (arg1.target as GButton).name;
                loc2 = new GangFightsReplyData();
                loc2.entityId = this._playerMiniInfo.entityId;
                if (loc1 != "ok") 
                {
                    loc2.isAgree = false;
                }
                else 
                {
                    loc2.isAgree = true;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.GangFightsReplyApply, loc2));
                Dispatcher.dispatchEvent(new DataEvent(EventName.GangFightsDelApplyRequest, this._msg));
            }
            return;
        }

        /* internal  */onPlayerTxtClickHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (this._playerMiniInfo) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerInfo_view, this._playerMiniInfo.entityId));
            }
            return;
        }

        /* internal  */onRequestTxtClickHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            return;
        }

        /* internal */ /* var */_campTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_playerTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_werfareTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_requestTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_okBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ /* var */_campColor: string;

        /* internal */ /* var */_campName: string;

        /* internal */ /* var */_msg: SGangFightsApplyTeam;

        /* internal */ /* var */_playerMiniInfo: PlayerMiniInfo;
    }
